package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.base.BaseModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.SetRewardContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Subscriber;

/**
 * Created by Jiangzx on 2017/11/3 11:10.
 */

public class SetRewardPresenter extends BasePresenter implements SetRewardContract.Presenter {
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    private SetRewardContract.View view;
    @Inject
    public SetRewardPresenter(SetRewardContract.View view){
        this.view=view;
    }

    @Override
    public void setSepPercent(int saleId, double percent) {
        view.showLoadingDialog(mContext.getString(R.string.text_wait_a_moment));
        rsaJsonUtil.put("salesID",saleId);
        rsaJsonUtil.put("ratio",percent);
        ApiServiceHelper.
                appointThreadNormal(apiService.setSepPercent(rsaJsonUtil.getRsaParams())).
                subscribe(new Subscriber<BaseModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(BaseModel baseModel) {
                        view.closeLoadingDialog();
                        view.onSepPercentSuccess();
                    }
                });
    }
}
